<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/2/28
 * Time: 下午5:40
 */

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\SupQualifyCategory;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Encore\Admin\Controllers\ModelForm;
class SupQualifyCateController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header('资质一级分类列表');
            $content->description('');
            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header('编辑分类');
            $content->description('');
            $content->body($this->form('edit')->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header('添加分类');
            $content->description('');
            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid() {
        return Admin::grid(SupQualifyCategory::class, function (Grid $grid) {
            $grid->id('ID')->sortable();
            $grid->category_name('类别名称');
            $grid->type('资质类别')->display(function ($type){
                if($type == "1"){
                    return "PC端";
                }else{
                    return "H5";
                }
            });
            $grid->show_order('展示顺序');
            $grid->flag('是否生效')->display(function($flag){
                if( $flag==1 ) return '有效';
                return '无效';
            });
            $grid->updated_at('更新时间');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form($mode='')
    {
        return Admin::form(SupQualifyCategory::class, function (Form $form) use($mode){
            if($mode=='edit'){
                $form->display('id','ID');
                $form->display('created_at', '创建时间');
                $form->display('updated_at', '更新时间');
            }
            $form->text('category_name','类别名称');
            $form->text('show_order','展示顺序,越小越靠前');
            $form->select('flag', '是否生效')->options([0=>'否', 1=>'是']);



        });
    }
}